package cn.edu.neusoft.demo.hospital2.Controller;

import cn.edu.neusoft.demo.hospital2.Service.RoomService;
import cn.edu.neusoft.demo.hospital2.pojo.Room;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "*")
@Tag(name = "RoomController相关api")
@RequestMapping("/room")
public class RoomController {
    @Autowired
    private RoomService roomService;

    @ResponseBody
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public List<Room> getRoomList() {
        return roomService.selectList();
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public int addRoom(@RequestBody Room room) {
        return roomService.insert(room);
    }

    @RequestMapping(value = "/update",method = RequestMethod.PUT)
    public int updateRoom(@RequestBody Room room) {
        return roomService.updateById(room);
    }

    @RequestMapping(value = "/delete",method = RequestMethod.DELETE)
    public int deleteRoom(Integer roomId) {
        return roomService.deleteById(roomId);
    }

    @ResponseBody
    @RequestMapping(value = "/getById",method = RequestMethod.GET)
    public Room getRoom(Integer roomId) {
        return roomService.selectById(roomId);
    }

}
